use serde::{Deserialize};

#[derive(Deserialize, Debug, PartialEq)]
enum BuyOrSell {
    Buy,
    Sell,
}

#[cfg(test)]
mod test {
    use super::*;

    #[test]
    fn buy_or_sell_json(){
        let serialized = r#""Buy""#;
        let deserialized: BuyOrSell  = serde_json::from_str(serialized).unwrap();
        assert_eq!(BuyOrSell::Buy, deserialized);
    }

    #[test]
    fn struct_json(){
        #[derive(Deserialize)]
        struct Order {
            id: String,
            buy_or_sell: BuyOrSell,
        }
        let src = r#"{"id":"12345","buy_or_sell":"Buy"}"#;
        let o: Order = serde_json::from_str(src).unwrap();
        assert_eq!(o.id, "12345");
        assert_eq!(o.buy_or_sell, BuyOrSell::Buy);
    }
}
